#include "rclcpp/rclcpp.hpp"
#include <chrono>
//#include "app_serial.hpp"
#include "tcp_manager.h"

class Class_Auto : public rclcpp::Node
{
public:
    Class_Auto(std::string name) : Node(name)
    {
        RCLCPP_INFO(this->get_logger(), "%s Node has been started.", name.c_str());
        // Create a timer 5ms
        timer_Auto_Work = this->create_wall_timer(std::chrono::milliseconds(5),std::bind(&Class_Auto::Auto_Work_timerCallback, this));

        Net_Init_Thread = std::thread(&Class_Auto::Net_Work_Handle, this);
    }

    ~Class_Auto()
    {
        running_ = false;
        if (Net_Init_Thread.joinable()){
            Net_Init_Thread.join();
        }
    }

private:
    void Auto_Work_timerCallback()
    {
        //RCLCPP_INFO(this->get_logger(), "Timer callback triggered.");
        //APP_Auto_System_Cycle();
        App_Net_5msCycle();
    }

    void Net_Work_Handle()
    {
        while (1)
        {
            RCLCPP_INFO(this->get_logger(), "Running other program...");
            app_net_handle();
            std::this_thread::sleep_for(std::chrono::seconds(1)); 
        }
    }

    rclcpp::TimerBase::SharedPtr timer_Auto_Work;
    std::thread Net_Init_Thread;
    bool running_;
};

int main(int argc, char **argv)
{
    rclcpp::init(argc, argv);
    auto node = std::make_shared<Class_Auto>("Node_Auto");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}











